package com.homwee.listMenu.util.view;

import android.content.Context;


import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.homwee.factory.R;
import com.homwee.listMenu.util.MenuItemData;
import com.homwee.listMenu.util.MenuItemView;

public class ItemOptionInputView extends MenuItemView{
	RelativeLayout mImage;
	TextView mName;
	TextView mValue;
	TextView mDotL;
	TextView mDotM;
	TextView mDotR;
	RelativeLayout layout;
	public int mInputNum =0;
	public ItemOptionInputView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	public ItemOptionInputView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	public ItemOptionInputView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void initData() {
		// TODO Auto-generated method stub
		layout =(RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.menu_optionview, null);
		this.addView(layout);
		mImage =(RelativeLayout) layout.findViewById(R.id.ItemImage);
		mName =(TextView) layout.findViewById(R.id.ItemName);
		mValue =(TextView) layout.findViewById(R.id.Value);
		mDotL = (TextView) layout.findViewById(R.id.DotL);
		mDotM = (TextView) layout.findViewById(R.id.DotM);
		mDotR = (TextView) layout.findViewById(R.id.DotR);
		mDotL.setVisibility(View.GONE);
		mDotM.setVisibility(View.GONE);
		mDotR.setVisibility(View.GONE);
		mMenuData.setOnValueChange(new MenuItemData.onValueChange() {
			
			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v("tv","OptionView valueChange");
				mValue.setText(mMenuData.mInitValue+""); 
			}
		});
	}
	@Override
	public void update() {
		// TODO Auto-generated method stub
		Log.v("zt","update1");
		if(mMenuData.isEnable){
			mName.setTextColor(Color.WHITE);
			mValue.setTextColor(Color.WHITE);
		}else{
			mDotM.setTextColor(Color.GRAY);
			mName.setTextColor(Color.GRAY);
			mValue.setTextColor(Color.GRAY);
		}
		mImage.setBackgroundResource(mMenuData.mNameImage);
		mName.setText(mMenuData.mName);
		mValue.setText(mMenuData.mInitValue+"");
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		Log.v("tv","onKeyDown ItemOptionInputView");
		switch(keyCode){
			case KeyEvent.KEYCODE_0:
			case KeyEvent.KEYCODE_1:		
			case KeyEvent.KEYCODE_2:		
			case KeyEvent.KEYCODE_3:		
			case KeyEvent.KEYCODE_4:		
			case KeyEvent.KEYCODE_5:		
			case KeyEvent.KEYCODE_6:		
			case KeyEvent.KEYCODE_7:		
			case KeyEvent.KEYCODE_8:		
			case KeyEvent.KEYCODE_9:
				mInputNum =mInputNum*10+(keyCode-KeyEvent.KEYCODE_0);
				if(mInputNum >mMenuData.mMaxValue){
					mInputNum =(keyCode-KeyEvent.KEYCODE_0);
				}
				mMenuData.mInitValue =mInputNum;
				mMenuData.valueChange();
				break;
			case KeyEvent.KEYCODE_DPAD_LEFT:
				break;
			case KeyEvent.KEYCODE_DPAD_RIGHT:	
				break;
			default:
				break;
		} 
		return false;
	}
}